#include<iostream>

#include<string.h>

using namespace std;

//回文字符串的递归实现

int Huiwen(int low, int high, char* str, int length)

{

if (length == 1 || length == 0)

{

return 1;

}

if (str[low] != str[high])

{

return 0;

}

return Huiwen(low + 1, high - 1, str, length - 2);

}

//回文字符串的递推实现

bool HuiWen(char *str,int length)

{

if(length==1||length==0)

{

return true;

}

for(int i=0,j=length-1;j>i;i++,j--)

{

if(str[i]!=str[j])

{

return false;

}

}

return true;

}

int main()

{

char str[] ="aba";

int length = strlen(str);

cout<<"递归实现结果"<<endl;

HuiWen( str, length);

for (int i = 0; i < length; i++)

{

cout << str[i];

}

if (HuiWen( str, length))

{

cout << " is a pilindrome";

}

else

{

cout << " is not a pilindrome";

}

cout<<endl;

cout<<"递推实现结果"<<endl;

Huiwen(0,length-1,str,length);

for (int i = 0; i < length; i++)

{

cout << str[i];

}

if (HuiWen( str, length))

{

cout << " is a pilindrome";

}

else

{

cout << " is not a pilindrome";

}

return 0;

}